#include "ProjectManager/newproject.h"


NewProject::NewProject()
{
    m_Layout    =   new QFormLayout();

    m_ProjectName       =   new QLineEdit("Name");
    m_ProjectPath       =   new QLineEdit("Path");
    m_ChoosePathButton  =   new QPushButton("Path");
    m_Validation        =   new QPushButton("Validation");

    m_Layout->addRow(m_ProjectName);
    m_Layout->addRow(m_ProjectPath);
    m_Layout->addRow(m_ChoosePathButton, m_Validation);

    setLayout(m_Layout);

    connect(m_Validation,       SIGNAL(clicked()), this, SLOT(SaveProject()));
    connect(m_ChoosePathButton, SIGNAL(clicked()), this, SLOT(SelectPath()));
}

void NewProject::SaveProject()
{
    // Je récupère les 2 strings des QLineEdit
    string path =   m_ProjectPath->text().toStdString();
    string name =   m_ProjectName->text().toStdString();

    // J'utilise une stringstream pour concatener les 2 chaînes
    stringstream   pathname (stringstream::in | stringstream::out);

    pathname<<path<<"/"<<name<<".pxd";

    // Création du fichier projet

    Project * proj  =   new Project(path, name );

    emit ProjectCreated(proj);

    close();
}

void NewProject::SelectPath()
{
    QString pathName =    QFileDialog::getExistingDirectory(this, tr("Changer path"));

    m_ProjectPath->setText( pathName);
}
